package cn.zn.controller.system;

import cn.zn.base.annotation.Log;
import cn.zn.base.bean.dto.ResultData;
import cn.zn.base.common.enums.BusinessType;
import cn.zn.base.common.utils.ResultUtil;
import cn.zn.log.service.SysLoginRecordService;
import cn.zn.log.vo.SysLoginRecordPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 系统访问记录
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/logs/login")
public class SysLoginRecordController {

    @Autowired
    private SysLoginRecordService loginRecordService;

    @PreAuthorize("@ss.hasPermi('log:login:list')")
    @GetMapping("/list")
    public ResultData list(SysLoginRecordPageVo vo) {
        Object result = loginRecordService.selectLoginRecordList(vo);
        return ResultUtil.success(result);
    }

    @PreAuthorize("@ss.hasPermi('log:login:remove')")
    @Log(title = "登录日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{infoIds}")
    public ResultData remove(@PathVariable String[] infoIds) {
        loginRecordService.deleteLoginRecordByIds(infoIds);
        return ResultUtil.success();
    }

    @PreAuthorize("@ss.hasPermi('log:login:remove')")
    @Log(title = "登录日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public ResultData clean() {
        loginRecordService.cleanLoginRecord();
        return ResultUtil.success();
    }
}
